package com.hj.aimin.auth.Service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.hj.aimin.auth.Service.UserService;
import com.hj.aimin.auth.dto.UserDto;
import com.hj.aimin.auth.entity.Address;
import com.hj.aimin.auth.entity.User;
import com.hj.aimin.auth.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private final UserMapper userMapper;

    @Override
    public List<UserDto> getJoin() {
        MPJLambdaWrapper<User> wrapper = new MPJLambdaWrapper<User>()
                .selectAll(User.class)//查询user表全部字段
                .select(Address::getCity, Address::getAddress)
                .leftJoin(Address.class, Address::getUserId, User::getId);

        List<UserDto> userList = userMapper.selectJoinList(UserDto.class, wrapper);

        return userList;
    }
}
